Merge "Proper namespace handling for WikiImporter"
[lhc/web/wiklou.git] / includes / specials / SpecialImport.php
index eab4784..9e9f8c0 100644 (file)
@@ -30,6 +30,7 @@
  * @ingroup SpecialPage
  */
 class SpecialImport extends SpecialPage {
+       private $sourceName = false;
        private $interwiki = false;
        private $subproject;
        private $fullInterwikiPrefix;
@@ -46,17 +47,20 @@ class SpecialImport extends SpecialPage {
         */
        public function __construct() {
                parent::__construct( 'Import', 'import' );
-               $this->namespace = $this->getConfig()->get( 'ImportTargetNamespace' );
        }
 
        /**
         * Execute
         * @param string|null $par
+        * @throws PermissionsError
+        * @throws ReadOnlyError
         */
        function execute( $par ) {
                $this->setHeaders();
                $this->outputHeader();
 
+               $this->namespace = $this->getConfig()->get( 'ImportTargetNamespace' );
+
                $this->getOutput()->addModules( 'mediawiki.special.import' );
 
                $user = $this->getUser();
@@ -98,7 +102,7 @@ class SpecialImport extends SpecialPage {
                $isUpload = false;
                $request = $this->getRequest();
                $this->namespace = $request->getIntOrNull( 'namespace' );
-               $sourceName = $request->getVal( "source" );
+               $this->sourceName = $request->getVal( "source" );
 
                $this->logcomment = $request->getText( 'log-comment' );
                $this->pageLinkDepth = $this->getConfig()->get( 'ExportMaxLinkDepth' ) == 0
@@ -109,14 +113,14 @@ class SpecialImport extends SpecialPage {
                $user = $this->getUser();
                if ( !$user->matchEditToken( $request->getVal( 'editToken' ) ) ) {
                        $source = Status::newFatal( 'import-token-mismatch' );
-               } elseif ( $sourceName == 'upload' ) {
+               } elseif ( $this->sourceName == 'upload' ) {
                        $isUpload = true;
                        if ( $user->isAllowed( 'importupload' ) ) {
                                $source = ImportStreamSource::newFromUpload( "xmlimport" );
                        } else {
                                throw new PermissionsError( 'importupload' );
                        }
-               } elseif ( $sourceName == "interwiki" ) {
+               } elseif ( $this->sourceName == "interwiki" ) {
                        if ( !$user->isAllowed( 'import' ) ) {
                                throw new PermissionsError( 'import' );
                        }
@@ -156,7 +160,7 @@ class SpecialImport extends SpecialPage {
                                array( 'importfailed', $source->getWikiText() )
                        );
                } else {
-                       $importer = new WikiImporter( $source->value );
+                       $importer = new WikiImporter( $source->value, $this->getConfig() );
                        if ( !is_null( $this->namespace ) ) {
                                $importer->setTargetNamespace( $this->namespace );
                        }
@@ -250,7 +254,8 @@ class SpecialImport extends SpecialPage {
                                        Xml::label( $this->msg( 'import-comment' )->text(), 'mw-import-comment' ) .
                                        "</td>
                                        <td class='mw-input'>" .
-                                       Xml::input( 'log-comment', 50, '',
+                                       Xml::input( 'log-comment', 50,
+                                               ( $this->sourceName == 'upload' ? $this->logcomment : '' ),
                                                array( 'id' => 'mw-import-comment', 'type' => 'text' ) ) . ' ' .
                                        "</td>
                                </tr>
@@ -430,7 +435,8 @@ class SpecialImport extends SpecialPage {
                                        Xml::label( $this->msg( 'import-comment' )->text(), 'mw-interwiki-comment' ) .
                                        "</td>
                                        <td class='mw-input'>" .
-                                       Xml::input( 'log-comment', 50, '',
+                                       Xml::input( 'log-comment', 50,
+                                               ( $this->sourceName == 'interwiki' ? $this->logcomment : '' ),
                                                array( 'id' => 'mw-interwiki-comment', 'type' => 'text' ) ) . ' ' .
                                        "</td>
                                </tr>
@@ -515,13 +521,14 @@ class ImportReporter extends ContextSource {
 
        /**
         * @param Title $title
-        * @param Title $origTitle
+        * @param ForeignTitle $foreignTitle
         * @param int $revisionCount
         * @param int $successCount
         * @param array $pageInfo
         * @return void
         */
-       function reportPage( $title, $origTitle, $revisionCount, $successCount, $pageInfo ) {
+       function reportPage( $title, $foreignTitle, $revisionCount,
+                       $successCount, $pageInfo ) {
                $args = func_get_args();
                call_user_func_array( $this->mOriginalPageOutCallback, $args );
 
@@ -550,7 +557,7 @@ class ImportReporter extends ContextSource {
                                $log->addEntry( 'upload', $title, $detail, array(), $this->getUser() );
                        } else {
                                $interwiki = '[[:' . $this->mInterwiki . ':' .
-                                       $origTitle->getPrefixedText() . ']]';
+                                       $foreignTitle->getFullText() . ']]';
                                $detail = $this->msg( 'import-logentry-interwiki-detail' )->numParams(
                                        $successCount )->params( $interwiki )->inContentLanguage()->text();
                                if ( $this->reason ) {
@@ -576,7 +583,7 @@ class ImportReporter extends ContextSource {
                                $page = WikiPage::factory( $title );
                                # Update page record
                                $page->updateRevisionOn( $dbw, $nullRevision );
-                               wfRunHooks(
+                               Hooks::run(
                                        'NewRevisionFromEditComplete',
                                        array( $page, $nullRevision, $latest, $this->getUser() )
                                );